import Vue from 'vue'
import App from './App.vue'
import axios from 'axios'
import ElementUI from "element-ui";
import "element-ui/lib/theme-chalk/index.css";
import router from './router'
import store from './store'

Vue.use(ElementUI);
//展示图片拼接地址
// Vue.prototype.imageapi = 'http://localhost/essadmin/public'
Vue.prototype.imageapi = 'https://ess-admin.wushun220.xyz/essadmin/public'
    //上传图片拼接地址
    // Vue.prototype.uploadimageapi = 'http://localhost/essadmin/public/index.php'
Vue.prototype.uploadimageapi = 'https://ess-admin.wushun220.xyz/essadmin/public/index.php'

Vue.config.productionTip = false
    //服务器接口地址
Vue.prototype.$http = axios;
// axios.defaults.baseURL = 'http://localhost/essadmin/public/index.php'
axios.defaults.baseURL = 'https://ess-admin.wushun220.xyz/essadmin/public/index.php'
new Vue({
    mode: 'history',
    router,
    store,
    render: h => h(App)
}).$mount('#app')

// 点击置顶
router.beforeEach((to, from, next) => {
    document.body.scrollTop = 0
        // firefox
    document.documentElement.scrollTop = 0
    next()
})

//判断是否登录
router.beforeEach((to, from, next) => {
    if (to.meta.requiresAuth) {
        //这里判断用户是否登录，验证本地存储是否有sessionStorage
        if (!sessionStorage.getItem('loginname')) { // 判断当前的sessionStorage是否存在
            next({
                path: '/login',
                query: { redirect: to.fullPath } //登录成功后重定向到当前页面
            })
        } else {
            next()
        }
    } else {
        next() // 确保一定要调用 next()
    }
})